package oop.core.med;
import java.util.Map;

import oop.core.entity.Avatar;
import oop.core.item.TakeableItem;
import oop.core.map.*;

public class ItemPlacementMediator {
	private Map<Location, TakeableItem> takeableItemMap;
	private Avatar avatar;
	
	public ItemPlacementMediator(Map<Location, TakeableItem> takeableItemMap, Avatar avatar){
		this.takeableItemMap=takeableItemMap;
		this.avatar = avatar;
	}
	
	public void dropItem( int index )
	{
		TakeableItem ti = avatar.getItem( index ); 
		if( ti != null )
		{
			if(dropItem( avatar.getLoc(), ti ))
			{
				avatar.removeItem(index);
			}
				
		}
	}
	
	public boolean dropItem(Location loc, TakeableItem item)
	{
		if(takeableItemMap.get(loc) == null)
		{
			takeableItemMap.put(loc, item);
			return true;
		}
		return false;
		//If the item already existed on the cell, you cannot put it down.
	}
}
